package cn.lingyan.service.impl;

import java.io.Serializable;
import java.util.List;

import cn.lingyan.dao.CommonDAO;
import cn.lingyan.entity.SaleOrder;
import cn.lingyan.entity.SaleOrderLine;
import cn.lingyan.service.OrderService;

public class OrderServiceImpl implements OrderService{
	//DAO
	private CommonDAO commonDAO = null;
	//Setter方法，用于注入
	public void setCommonDAO(CommonDAO dao){
		this.commonDAO = dao;
	}
	// 业务方法
	/**
	 * 添加订单
	 * @param o
	 */
	public void add(SaleOrder o){
		this.commonDAO.add(o);
	}
	public SaleOrder get(Serializable id) {
		SaleOrder ret = (SaleOrder)this.commonDAO.get(SaleOrder.class, id);
		return ret;
	}
	public SaleOrder getWithLines(Serializable id) {
		SaleOrder ret = null;
		String hql = "select o from SaleOrder o left join fetch o.saleOrderLines where o.odrId="
			+id + " ";
		List list = this.commonDAO.search(hql);
		if(null!=list && !list.isEmpty()){
			ret = (SaleOrder)list.get(0);
		}
		return ret;
	}
	public void addDetail(SaleOrderLine o) {
		this.commonDAO.add(o);
	}
}
